--[[
描述 ： 用户提示框
作者 ： gengdy
时间 ： 15/04/15
]]
UIUserPop = Class(MLView,'UIUserPop');
UIUserPop.mItemsHeight = nil;
UIUserPop.mWidth       = nil;
UIUserPop.mList        = nil;
UIUserPop.viewCtrl         = nil;

UIUserPop.onClickEvent       = nil;
UIUserPop.items    = nil;
UIUserPop.mPopCanvas    = nil;
UIUserPop.mPopCover    = nil;
--[[
功能   ： new 用户提示框 控件
参数   ： items       --  数据集合
参数   ： viewCtrl       --  根view
返回   ： 用户提示框  实例
]]
function UIUserPop:init(items,viewCtrl,id)

  self.w, self.h = viewCtrl.rootView:getWH();
  self:initView(AW(120),AH(240),viewCtrl,id);
  self.weekTable.mViewCtrl = viewCtrl;

  self.items = items ;
  self.mItemsHeight = AH(40);
  self.mWidth       = AW(120);

  self:draw();
  self:PopView(self)
  return self;
end

--[[
功能   ： 画控件
参数   ： 无
返回   ： 无
]]
function UIUserPop:draw()

  self.mList   = MLScrollView.new():initScrollView(self.mWidth, AH(240) ,false,self.weekTable.mViewCtrl);

  for var=1 , #self.items do
    local ub =  UIButton.new():init(self.mWidth, self.mItemsHeight,self.weekTable.mViewCtrl,var);
    ub.text = self.items[var];
    ub.fontHeight = AW(14);
    ub.fontColor = UIColor.COLOR_WHITE;
    ub.bgImage = UIImage.imageName('system/sys_btn.png');
    ub.focusImage = UIImage.imageName('system/sys_btn_h.png');
    ub.tag = var;
    ub.parent = self;
    ub.onClick = function ()
      -- body
      if self.onClickEvent then
        self.onClickEvent(ub.tag);
      end
      self:ClosePop(self);
    end;
    ub:show();
    self.mList:add(ub);
  end

  self:add(self.mList, 0 , -(self.mItemsHeight *5));

end


--[[
功能   ： Pop View
参数   ： 无
返回   ： 无
]]
function UIUserPop:PopView(view)

  local scr = self.weekTable.mViewCtrl.rootView;
  local sw, sh = MLNative.deviceWH();
  local w, h = view:getWH();
  if self.mPopCanvas  then return; end

  self.mPopCover = MLView.new():initView(sw, sh,self.weekTable.mViewCtrl);

  self.mPopCover:setColor(0x000000);
  self.mPopCover:setAlpha(0.1);
  self.mPopCover.onClick = function (  )
    MLNative.genAnimate(
      function ()
      end, 200,self.weekTable.mViewCtrl);
    self.mList:setXY( 0 ,-(self.mItemsHeight *6));
    MLNative.doAnimate(self.weekTable.mViewCtrl);
    self.mPopCanvas = nil ;
    self:ClosePop(self);
    
  end
  scr:add(self.mPopCover, 0, 0);
  local height = 0 ;
  if self.weekTable.mViewCtrl.headView then
    height = self.weekTable.mViewCtrl.headView:getHeight()
  end
  scr:add(view, sw-w,height);
  
  MLNative.genAnimate(
    function ()
    end, 200,self.weekTable.mViewCtrl );
  self.mList:setXY( 0, 0);
  MLNative.doAnimate(self.weekTable.mViewCtrl);
  
  self.mPopCanvas = view;
end

--[[
功能   ： Close View
参数   ： 无
返回   ： 无
]]
function UIUserPop:ClosePop(view)
  
  if self.mPopCover then self.weekTable.mViewCtrl.rootView:del(self.mPopCover); end
  if self.mPopCanvas then self.weekTable.mViewCtrl.rootView:del(self.mPopCanvas); end
  self.mPopCover = nil;
  self.mPopCanvas = nil;
end


function UIUserPop:destroy()

  UIUserPop.mItemsHeight = nil;
  UIUserPop.mWidth       = nil;
  UIUserPop.mList        = nil;
  UIUserPop.mCurSel      = nil;
  UIUserPop.mRootView    = nil;
  UIUserPop.mOnItemClick  = nil;
  UIUserPop.mTemp         = {};
  UIUserPop.viewCtrl         = nil;
end

--[[
功能   ： 显示控件
参数   ： 无
返回   ： 无
]]
function UIUserPop:show()
  self:draw();
  self:PopView(self);
end

--[[

local info = {'1111','2222','3333','4444'}
local view  = UIUserPop.new():init(info, self);
view.onClickEvent = function ( v )
    -- body
    print('rrrrrrrrrrrrr===',v)
end

]]
